package com.hitqz.robot.camera.entity;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import com.hitqz.robot.camera.callback.HkAlarmMessageCallBack;
import com.hitqz.robot.camera.callback.HkTemperatureCallBack;
import com.hitqz.robot.camera.callback.HkVoiceDataCallBack;
import com.hitqz.robot.camera.dto.AreaTemplateDTO;
import com.hitqz.robot.camera.dto.EquipmentLoginParamsDto;
import com.hitqz.robot.camera.service.HCNetSDK;
import com.hitqz.robot.camera.service.PlayCtrl;
import com.sun.jna.ptr.IntByReference;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.concurrent.TimeUnit;

@Component
public class ConstantsFace {


    /**
     * **************海康参数***********************************
     */
    public static HCNetSDK HK_NET_SDK = null;

    public static PlayCtrl HK_PLAY_SDK = null;

    public static HkAlarmMessageCallBack hkAlarmMessageCallBack = null;

    public static HkVoiceDataCallBack hkVoiceDataCallBack = null;

    public static HkTemperatureCallBack hkTemperatureCallBack = null;

    public static HCNetSDK.NET_DVR_THERMOMETRY_UPLOAD HK_THERMOMETRY_UPLOAD = null;
    //海康播放库
    public static IntByReference m_lPort= new IntByReference(1);
    //海康已登录设备
    public static Map<String, HkCameraDriver> HK_CAMERA_DRIVER_MAP = new HashMap<>(8);
    //海康登录失败设备
    public static List<EquipmentLoginParamsDto> HK_LOGIN_FAIL_LIST = new ArrayList<>(8);

    public static String HK_SET_FOCUS_XML="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
            "<PTZData>" +
            "<AbsoluteHigh>" +
            "<absoluteZoom>10</absoluteZoom>" +
            "<azimuth>0</azimuth>" +
            "<elevation>0</elevation>" +
            "</AbsoluteHigh>" +
            "</PTZData>";

    public static String HK_SET_REGIONAL_FOCUS_XML="<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<RegionalFocus>" +
            "<StartPoint>" +
            "<positionX>392</positionX>" +
            "<positionY>816</positionY>" +
            "</StartPoint><EndPoint>" +
            "<positionX>647</positionX>" +
            "<positionY>350</positionY>" +
            "</EndPoint></RegionalFocus>";

    //温度
    public static Table<String, Integer, AreaTemplateDTO> TEMPERATURE_TABLE = HashBasedTable.create();


    //语音播报
    public static boolean voicePlayEnable;
    public static String voicePlayIp = "";


    private static final Cache<String, Boolean> playMp4Flag = CacheBuilder
            .newBuilder()
            .maximumSize(10)
            .expireAfterWrite(1, TimeUnit.SECONDS)
            .build();

    public static boolean getPlayMp4Flag(String ip) {
        Boolean aBoolean = playMp4Flag.getIfPresent(ip);
        return aBoolean != null && aBoolean;
    }

    public static void setPlayMp4Flag(String ip, boolean flag){
        playMp4Flag.put(ip, flag);
    }



}
